﻿using System;
using System.Data;

namespace Solution.CMS
{
    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            var contactDs = new DataSet();

            contactDs.ReadXml(Server.MapPath("/contact.xml"));

            txtPhone.Text = contactDs.Tables[0].Rows[0]["phone"].ToString();
            txtEmail.Text = contactDs.Tables[0].Rows[0]["email"].ToString();
            txtAddress.Text = contactDs.Tables[0].Rows[0]["address"].ToString();
            htmlInfo.Html = contactDs.Tables[0].Rows[0]["info"].ToString();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var contactDs = new DataSet();

            contactDs.ReadXml(Server.MapPath("/contact.xml"));

            contactDs.Tables[0].Rows[0]["phone"] = txtPhone.Text;
            contactDs.Tables[0].Rows[0]["email"] = txtEmail.Text;
            contactDs.Tables[0].Rows[0]["address"] = txtAddress.Text;
            contactDs.Tables[0].Rows[0]["info"] = htmlInfo.Html;

            contactDs.WriteXml(Server.MapPath("/contact.xml"));
            Response.Redirect("default.aspx");
        }
    }
}